const { docSchedulingModel, OrderModel } = require("../model");

// 定义一个函数来执行删除操作
// 定义一个函数来执行删除操作  
 async function deleteOldData() {  
    try {  
      const currentHour = new Date().getHours();  
      const currentMinute = new Date().getMinutes();  
    
      // 检查当前时间是否在18:30之后  
      if (currentHour >= 18 && currentMinute >= 30) {  
        // 执行批量删除操作  
        const result = await docSchedulingModel.deleteMany({  
          status: 1, // 根据您的实际需求设置删除条件  
        });  
        const result2 = await OrderModel.deleteMany({
            registerStatus:2
        })
    
        console.log(`Deleted ${result.deletedCount} documents.`);  
        console.log(`Deleted ${result2.deletedCount} documents.`);  
      }  
    } catch (err) {  
      console.error('Error deleting data:', err);  
    }  
  }  

  module.exports = deleteOldData
